//------------------------------------------------------------------------------
#include "application.h"
#include <QDebug>
//------------------------------------------------------------------------------
Application* Application::m_instance = 0;
//------------------------------------------------------------------------------
Application::Application(int& argc, char* argv[]) : QApplication(argc, argv){
	setApplicationName(APPLICATION_NAME);
	setApplicationVersion(APPLICATION_VERSION);
	setOrganizationName(ORGANIZATION_NAME);

	// We store the list because it is said in the documentation that the call
	// to 'arguments' is slow
	m_args = arguments();

	m_preferences = 0;
}
//------------------------------------------------------------------------------
Application::~Application(){
	if(m_preferences){
		m_preferences->sync();
		delete m_preferences;
	}
}
//------------------------------------------------------------------------------
void Application::create(int& argc, char* argv[]){
	if(m_instance != 0)
		return;

	m_instance = new Application(argc, argv);
}
//------------------------------------------------------------------------------
void Application::destroy(){
	delete m_instance;
	m_instance = 0;
}
//------------------------------------------------------------------------------
QSettings * Application::preferences(){
	if(!m_preferences)
		m_preferences = new QSettings(ORGANIZATION_NAME, APPLICATION_NAME, this);

	return m_preferences;
}
//------------------------------------------------------------------------------
